from content.models import Word
from content.models import Picture
from content.models import Article
from datetime import datetime

now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def get_word_for_index():
    words = Word.objects.all().order_by('-id')
    if words.count() < 2:
        word1 = {'date': now, 'word': '', 'author': ''}
        word2 = {'date': now, 'word': '', 'author': ''}
        words = [word1, word2]
        return words
    return words


def get_pic_for_index():
    pic = Picture.objects.all().order_by('-id')
    if pic.count() < 2:
        url_example = 'http://7xr8b4.com1.z0.glb.clouddn.com/5c46a6ec8a136327b2d00bf3958fa0ec09fac74f.jpg'
        pic1 = {'des': '示例图片', 'url': url_example}
        pic2 = {'des': '示例图片', 'url': url_example}
        pic = [pic1, pic2]
        return pic
    return pic


def get_article_for_blog():
    blog = Article.objects.all().order_by('-id')
    if blog.count() < 1:
        blog = {'date': now, 'content': "展示文章", 'author': '我'}
        return blog
    return blog
